import http from '@/utils/HttpClient'

export const LOAD_STUDENT_INFO = 'LOAD_STUDY_INFO'

export const LOAD_STUDY_TASK = 'LOAD_STUDY_TASK'

export const LOAD_HISTORY_TASK = 'LOAD_HISTORY_TASK'

export const LOAD_ACHIEVEMENT = 'LOAD_ACHIEVEMENT'

export const LOAD_STUDENT_RANK = 'LOAD_STUDENT_RANK'

export const LOAD_UNGRAD_STUDENTS = 'LOAD_UNGRAD_STUDENTS'

export const LOAD_GRAD_STUDENTS = 'LOAD_GRAD_STUDENTS'
export const LOAD_TEACHER_INFO = 'LOAD_TEACHER_INFO'
export const LOAD_TEACHER_RANK = 'LOAD_TEACHER_RANK'

export const LOAD_TEACHER_ADMIN = 'LOAD_TEACHER_ADMIN'
export const LOAD_GRAD_STUDENT_ADMIN = 'LOAD_GRAD_STUDENT_ADMIN'
export const LOAD_UNGRAD_STUDENT_ADMIN = 'LOAD_UNGRAD_STUDENT_ADMIN'
export const LOAD_AUDIT_ADMIN = 'LOAD_AUDIT_ADMIN'
export const UPDATE_TAB_GRAD = 'UPDATE_TAB_GRAD'

export const UPDATE_CURRENT_TASK = 'UPDATE_CURRENT_TASK'
export async function loadData (state, name, route, params = {}) {
  var store = state[name]
  if (store && store.items.length === store.totalCount) {
    return store
  }
  var requestData = {
    SkipCount: store === null ? 0 : store.items.length,
    MaxResultCount: 10
  }
  Object.assign(requestData, params)
  var data = await http.get({ url: route, data: requestData })
  if (store !== null) {
    var items = store.items.concat(data.items)
    data.items = items
  }
  return data
}
